package org.example.hadoop3;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;
/**
 * 使用方法
 * mapred-site.xml mapreduce.job.partitioner.class
 * job.setPartitionerClass(CustomPartitioner.class)
 * job.setNumReduceTask(5);
  */
public class CustomPartitioner extends Partitioner<Text, FlowBean> {

    /**
     *
     * @param text
     * @param flowBean
     * @param i
     * @return
     */
    @Override
    public int getPartition(Text text, FlowBean flowBean, int i) {
        String phone = text.toString();
        int partition = 0;
        if (phone.startsWith("136")) {
            partition = 0;
        } else if (phone.startsWith("137")) {
            partition = 1;
        }  else if (phone.startsWith("138")) {
            partition = 2;
        } else if (phone.startsWith("139")) {
            partition = 3;
        } else {
            partition = 4;
        }
        return partition;
    }
}
